package com.nbjtjc.safe.api.sys;

import com.nbjtjc.common.validator.ValidatorUtils;
import com.nbjtjc.common.validator.group.DeleteGroup;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.model.sys.SysUserCompanyData;
import com.nbjtjc.safe.service.sys.SysUserCompanyDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther guqianbin
 * @date 2018/8/13 13:31
 **/
@RestController
@RequestMapping("/companyData")
@CrossOrigin("*")
public class SysUserCompanyDataController {

    @Autowired
    private SysUserCompanyDataService sysUserCompanyDataService;

    @PostMapping("/find")
    public Result find(SysUserCompanyData sysUserCompanyData){
        Result result=new Result();
        result.setData(sysUserCompanyDataService.find(sysUserCompanyData));
        return result;
    }

    @PostMapping("/add")
    public Result add(SysUserCompanyData sysUserCompanyData){
        ValidatorUtils.validateEntity(sysUserCompanyData);
        Result result=new Result();
        result.setData(sysUserCompanyDataService.add(sysUserCompanyData));
        return result;
    }

    @PostMapping("/delete")
    public Result delete(SysUserCompanyData sysUserCompanyData){
        ValidatorUtils.validateEntity(sysUserCompanyData, DeleteGroup.class);
        Result result=new Result();
        if (sysUserCompanyDataService.delete(sysUserCompanyData)){
            result.setSuccess(true);
        }else{
            result.setFalse();
        }
        return result;
    }
}
